using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using PlugNT.Safe;
using PlugNT.Cms.Custom;
using PlugNT.Database;
using PlugNT.Cms.Model;

namespace PlugNT.Cms.BLL
{
    public class Attachment
    {

        private static readonly PlugNT.Cms.DAL.Attachment dal = new PlugNT.Cms.DAL.Attachment();







        public AttachmentInfo GetAttachmentInfo(int id)
        {
            return dal.GetAttachmentInfo(id);

        }
        public int GetIdByFilePath(string filepath)
        {
            return dal.GetIdByFilePath(filepath);
        }






        public bool AddAttachment(AttachmentInfo model)
        {
            return dal.AddAttachment(model);
        }






        public bool Update(AttachmentInfo model)
        {
            return dal.Update(model);
        }

        public bool OperationDownCount(int id, string operation,int count)
        {
            return dal.OperationDownCount(id, operation, count);
        }







        public bool Delete(int id)
        {
            object fPath = dal.GetSingle("file_path", id);
            if (fPath != null)
            {
                string mPath = PlugNT.Common.Utils.GetMapPath(fPath.ToString());
                if (PlugNT.Common.Utils.FileExists(mPath))
                {
                    if (PlugNT.Common.Utils.DeleteFile(mPath))
                    {
                        return dal.Delete(id);
                    }
                }
                else
                {
                    return dal.Delete(id);
                }
            }
            return false;
        }


        public DataTable GetList(int sysModelId, string andWhere)
        {
            return dal.GetList(sysModelId, andWhere);
        }


        public DataTable GetList(int sysModelId, int topCount, int currPageCount, string andWhere, out int recordCount)
        {
            recordCount = dal.GetCount(sysModelId, andWhere);
            return dal.GetList(sysModelId, topCount, currPageCount, andWhere);
        }



    }
}

